home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / stdg44.exe / lha / HELLO.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  2KB  |  62 lines

  1. /*
  2.  * Hello Stdg World by Loki
  3.  *
  4.  *  An example program which shows how easy it is to program with Stdg.
  5.  *  The example creates a window and draws a string on to it.
  6.  *  There are 8 library functions and 7 variables used.
  7.  */
  8.  
  9. #include "stdg.h"
  10.  
  11. /*
  12.  *  The redraw function is called when a window needs redrawing.
  13.  *  It should redraw the entire window.
  14.  */
  15. void redraw(window *w)
  16. {
  17.     /*
  18.      * First, we calculate some heights and widths so
  19.      * we know where to place our message on the window.
  20.      * The point we find is the top-left point of the string.
  21.      */
  22.     char *hello_string = "Hello, World!";
  23.     long str_width = strwidth(sys_font, hello_string);
  24.     long str_height = sys_font->height;
  25.     long win_width = dx(w->r);  /* delta-x i.e. width */
  26.     long win_height = dy(w->r); /* delta-y i.e. height */
  27.  
  28.     point p = pt((win_width-str_width)/2, (win_height-str_height)/2);
  29.  
  30.     /*
  31.      * Now we actually draw the string on the window's bitmap w->b
  32.      * at point p using the system font and grey text.
  33.      */
  34.     draw_string(w->b, p, sys_font, hello_string, GREY);
  35. }
  36.  
  37. /*
  38.  *  The main function is where the program begins.
  39.  */
  40. int main(int argc, char **argv)
  41. {
  42.     window *w;
  43.  
  44.     /* Initilise the graphical interface. */
  45.     ginit("Hello Stdg World", NULL, NULL);
  46.  
  47.     /* Create a new window which is the size of the screen. */
  48.     w = new_window("Hello Window", rect(0,0,0,0), Titlebar|Maximize|Resize);
  49.  
  50.     /* Link our redraw function to this new window. */
  51.     set_winfns(w, NULL, NULL, &redraw);
  52.  
  53.     /* Display the window on the screen. */
  54.     show_window(w);
  55.  
  56.     /* Now poll for events but do nothing with them. */
  57.     while(1)
  58.         can_event();
  59.  
  60.     return 0;
  61. }
  62.